home *** CD-ROM | disk | FTP | other *** search
/ Computer Arts: Pro Software Skills - Photoshop / Computer Arts Pro Software Skills Photoshop.iso / pc / main.swf / scripts / __Packages / mx / video / NCManager.as < prev    next >
Encoding:
Text File  |  2011-06-06  |  26.5 KB  |  890 lines

  1. class mx.video.NCManager implements mx.video.INCManager
  2. {
  3.    var _timeoutIntervalId;
  4.    var _tryNCIntervalId;
  5.    var _timeout;
  6.    var _nc;
  7.    var _ncConnected;
  8.    var _isRTMP;
  9.    var _serverName;
  10.    var _wrappedURL;
  11.    var _portNumber;
  12.    var _appName;
  13.    var _contentPath;
  14.    var _streamName;
  15.    var _streamLength;
  16.    var _streamWidth;
  17.    var _streamHeight;
  18.    var _streams;
  19.    var _autoSenseBW;
  20.    var fpadZone;
  21.    var _payload;
  22.    var _connTypeCounter;
  23.    var _bitrate;
  24.    var _owner;
  25.    var _protocol;
  26.    var _smilMgr;
  27.    var mc;
  28.    var _ncUri;
  29.    var _fpadMgr;
  30.    var fallbackServerName;
  31.    var _tryNC;
  32.    static var version = "1.0.2.7";
  33.    static var shortVersion = "1.0.2";
  34.    var DEFAULT_TIMEOUT = 60000;
  35.    function NCManager()
  36.    {
  37.       this.initNCInfo();
  38.       this.initOtherInfo();
  39.       this._timeoutIntervalId = 0;
  40.       this._tryNCIntervalId = 0;
  41.       this._timeout = this.DEFAULT_TIMEOUT;
  42.       this._nc = undefined;
  43.       this._ncConnected = false;
  44.    }
  45.    function initNCInfo()
  46.    {
  47.       this._isRTMP = undefined;
  48.       this._serverName = undefined;
  49.       this._wrappedURL = undefined;
  50.       this._portNumber = undefined;
  51.       this._appName = undefined;
  52.    }
  53.    function initOtherInfo()
  54.    {
  55.       this._contentPath = undefined;
  56.       this._streamName = undefined;
  57.       this._streamLength = undefined;
  58.       this._streamWidth = undefined;
  59.       this._streamHeight = undefined;
  60.       this._streams = undefined;
  61.       this._autoSenseBW = false;
  62.       this.fpadZone = undefined;
  63.       this._payload = 0;
  64.       this._connTypeCounter = 0;
  65.       this.cleanConns();
  66.    }
  67.    function getTimeout()
  68.    {
  69.       return this._timeout;
  70.    }
  71.    function setTimeout(t)
  72.    {
  73.       this._timeout = t;
  74.       if(this._timeoutIntervalId != 0)
  75.       {
  76.          clearInterval(this._timeoutIntervalId);
  77.          this._timeoutIntervalId = setInterval(this,"_onFCSConnectTimeOut",this._timeout);
  78.       }
  79.    }
  80.    function getBitrate()
  81.    {
  82.       return this._bitrate;
  83.    }
  84.    function setBitrate(b)
  85.    {
  86.       if(this._isRTMP == undefined || !this._isRTMP)
  87.       {
  88.          this._bitrate = b;
  89.       }
  90.    }
  91.    function getVideoPlayer()
  92.    {
  93.       return this._owner;
  94.    }
  95.    function setVideoPlayer(v)
  96.    {
  97.       this._owner = v;
  98.    }
  99.    function getNetConnection()
  100.    {
  101.       return this._nc;
  102.    }
  103.    function getStreamName()
  104.    {
  105.       return this._streamName;
  106.    }
  107.    function isRTMP()
  108.    {
  109.       return this._isRTMP;
  110.    }
  111.    function getStreamLength()
  112.    {
  113.       return this._streamLength;
  114.    }
  115.    function getStreamWidth()
  116.    {
  117.       return this._streamWidth;
  118.    }
  119.    function getStreamHeight()
  120.    {
  121.       return this._streamHeight;
  122.    }
  123.    function connectToURL(url)
  124.    {
  125.       this.initOtherInfo();
  126.       this._contentPath = url;
  127.       if(this._contentPath == null || this._contentPath == "")
  128.       {
  129.          throw new mx.video.VideoError(mx.video.VideoError.INVALID_CONTENT_PATH);
  130.       }
  131.       var _loc2_ = this.parseURL(this._contentPath);
  132.       if(_loc2_.streamName == undefined || _loc2_.streamName == "")
  133.       {
  134.          throw new mx.video.VideoError(mx.video.VideoError.INVALID_CONTENT_PATH,url);
  135.       }
  136.       if(_loc2_.isRTMP)
  137.       {
  138.          var _loc4_ = this.canReuseOldConnection(_loc2_);
  139.          this._isRTMP = true;
  140.          this._protocol = _loc2_.protocol;
  141.          this._streamName = _loc2_.streamName;
  142.          this._serverName = _loc2_.serverName;
  143.          this._wrappedURL = _loc2_.wrappedURL;
  144.          this._portNumber = _loc2_.portNumber;
  145.          this._appName = _loc2_.appName;
  146.          if(this._appName == undefined || this._appName == "" || this._streamName == undefined || this._streamName == "")
  147.          {
  148.             throw new mx.video.VideoError(mx.video.VideoError.INVALID_CONTENT_PATH,url);
  149.          }
  150.          this._autoSenseBW = this._streamName.indexOf(",") >= 0;
  151.          return _loc4_ || this.connectRTMP();
  152.       }
  153.       var _loc3_ = _loc2_.streamName;
  154.       if(_loc3_.indexOf("?") < 0 && (_loc3_.length < 4 || _loc3_.slice(-4).toLowerCase() != ".txt") && (_loc3_.length < 4 || _loc3_.slice(-4).toLowerCase() != ".xml") && (_loc3_.length < 5 || _loc3_.slice(-5).toLowerCase() != ".smil"))
  155.       {
  156.          _loc4_ = this.canReuseOldConnection(_loc2_);
  157.          this._isRTMP = false;
  158.          this._streamName = _loc3_;
  159.          return _loc4_ || this.connectHTTP();
  160.       }
  161.       if(_loc3_.indexOf("/fms/fpad") >= 0)
  162.       {
  163.          try
  164.          {
  165.             return this.connectFPAD(_loc3_);
  166.          }
  167.          catch(err:Error)
  168.          {
  169.          }
  170.       }
  171.       this._smilMgr = new mx.video.SMILManager(this);
  172.       return this._smilMgr.connectXML(_loc3_);
  173.    }
  174.    function connectAgain()
  175.    {
  176.       var _loc2_ = this._appName.indexOf("/");
  177.       if(_loc2_ < 0)
  178.       {
  179.          _loc2_ = this._streamName.indexOf("/");
  180.          if(_loc2_ >= 0)
  181.          {
  182.             this._appName += "/";
  183.             this._appName += this._streamName.slice(0,_loc2_);
  184.             this._streamName = this._streamName.slice(_loc2_ + 1);
  185.          }
  186.          return false;
  187.       }
  188.       var _loc3_ = this._appName.slice(_loc2_ + 1);
  189.       _loc3_ += "/";
  190.       _loc3_ += this._streamName;
  191.       this._streamName = _loc3_;
  192.       this._appName = this._appName.slice(0,_loc2_);
  193.       this.close();
  194.       this._payload = 0;
  195.       this._connTypeCounter = 0;
  196.       this.cleanConns();
  197.       this.connectRTMP();
  198.       return true;
  199.    }
  200.    function reconnect()
  201.    {
  202.       if(!this._isRTMP)
  203.       {
  204.          throw new Error("Cannot call reconnect on an http connection");
  205.       }
  206.       this._nc.onStatus = function(info)
  207.       {
  208.          this.mc.reconnectOnStatus(this,info);
  209.       };
  210.       this._nc.onBWDone = function()
  211.       {
  212.          this.mc.onReconnected();
  213.       };
  214.       this._nc.connect(this._ncUri,false);
  215.    }
  216.    function onReconnected()
  217.    {
  218.       delete this._nc.onStatus;
  219.       delete this._nc.onBWDone;
  220.       this._ncConnected = true;
  221.       this._owner.ncReconnected();
  222.    }
  223.    function close()
  224.    {
  225.       if(this._nc)
  226.       {
  227.          this._nc.close();
  228.          this._ncConnected = false;
  229.       }
  230.    }
  231.    function helperDone(helper, success)
  232.    {
  233.       if(!success)
  234.       {
  235.          this._nc = undefined;
  236.          this._ncConnected = false;
  237.          this._owner.ncConnected();
  238.          this._smilMgr = undefined;
  239.          this._fpadMgr = undefined;
  240.          return undefined;
  241.       }
  242.       var _loc2_ = undefined;
  243.       var _loc4_ = undefined;
  244.       if(helper == this._fpadMgr)
  245.       {
  246.          _loc4_ = this._fpadMgr.rtmpURL;
  247.          this._fpadMgr = undefined;
  248.          _loc2_ = this.parseURL(_loc4_);
  249.          this._isRTMP = _loc2_.isRTMP;
  250.          this._protocol = _loc2_.protocol;
  251.          this._serverName = _loc2_.serverName;
  252.          this._portNumber = _loc2_.portNumber;
  253.          this._wrappedURL = _loc2_.wrappedURL;
  254.          this._appName = _loc2_.appName;
  255.          this._streamName = _loc2_.streamName;
  256.          var _loc5_ = this.fpadZone;
  257.          this.fpadZone = -1;
  258.          this.connectRTMP();
  259.          this.fpadZone = _loc5_;
  260.          return undefined;
  261.       }
  262.       if(helper != this._smilMgr)
  263.       {
  264.          return undefined;
  265.       }
  266.       this._streamWidth = this._smilMgr.width;
  267.       this._streamHeight = this._smilMgr.height;
  268.       _loc4_ = this._smilMgr.baseURLAttr[0];
  269.       if(_loc4_ != undefined && _loc4_ != "")
  270.       {
  271.          if(_loc4_.charAt(_loc4_.length - 1) != "/")
  272.          {
  273.             _loc4_ += "/";
  274.          }
  275.          _loc2_ = this.parseURL(_loc4_);
  276.          this._isRTMP = _loc2_.isRTMP;
  277.          this._streamName = _loc2_.streamName;
  278.          if(this._isRTMP)
  279.          {
  280.             this._protocol = _loc2_.protocol;
  281.             this._serverName = _loc2_.serverName;
  282.             this._portNumber = _loc2_.portNumber;
  283.             this._wrappedURL = _loc2_.wrappedURL;
  284.             this._appName = _loc2_.appName;
  285.             if(this._appName == undefined || this._appName == "")
  286.             {
  287.                this._smilMgr = undefined;
  288.                throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"Base RTMP URL must include application name: " + _loc4_);
  289.             }
  290.             if(this._smilMgr.baseURLAttr.length > 1)
  291.             {
  292.                _loc2_ = this.parseURL(this._smilMgr.baseURLAttr[1]);
  293.                if(_loc2_.serverName != undefined)
  294.                {
  295.                   this.fallbackServerName = _loc2_.serverName;
  296.                }
  297.             }
  298.          }
  299.       }
  300.       this._streams = this._smilMgr.videoTags;
  301.       this._smilMgr = undefined;
  302.       var _loc3_ = 0;
  303.       while(_loc3_ < this._streams.length)
  304.       {
  305.          _loc4_ = this._streams[_loc3_].src;
  306.          _loc2_ = this.parseURL(_loc4_);
  307.          if(this._isRTMP == undefined)
  308.          {
  309.             this._isRTMP = _loc2_.isRTMP;
  310.             if(this._isRTMP)
  311.             {
  312.                this._protocol = _loc2_.protocol;
  313.                if(this._streams.length > 1)
  314.                {
  315.                   throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"Cannot switch between multiple absolute RTMP URLs, must use meta tag base attribute.");
  316.                }
  317.                this._serverName = _loc2_.serverName;
  318.                this._portNumber = _loc2_.portNumber;
  319.                this._wrappedURL = _loc2_.wrappedURL;
  320.                this._appName = _loc2_.appName;
  321.                if(this._appName == undefined || this._appName == "")
  322.                {
  323.                   throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"Base RTMP URL must include application name: " + _loc4_);
  324.                }
  325.             }
  326.             else if(_loc2_.streamName.indexOf("/fms/fpad") >= 0 && this._streams.length > 1)
  327.             {
  328.                throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"Cannot switch between multiple absolute fpad URLs, must use meta tag base attribute.");
  329.             }
  330.          }
  331.          else if(this._streamName != undefined && this._streamName != "" && !_loc2_.isRelative && this._streams.length > 1)
  332.          {
  333.             throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"When using meta tag base attribute, cannot use absolute URLs for video or ref tag src attributes.");
  334.          }
  335.          this._streams[_loc3_].parseResults = _loc2_;
  336.          _loc3_ = _loc3_ + 1;
  337.       }
  338.       this._autoSenseBW = this._streams.length > 1;
  339.       if(!this._autoSenseBW)
  340.       {
  341.          if(this._streamName != undefined)
  342.          {
  343.             this._streamName += this._streams[0].parseResults.streamName;
  344.          }
  345.          else
  346.          {
  347.             this._streamName = this._streams[0].parseResults.streamName;
  348.          }
  349.          this._streamLength = this._streams[0].dur;
  350.       }
  351.       if(this._isRTMP)
  352.       {
  353.          this.connectRTMP();
  354.       }
  355.       else if(this._streamName != undefined && this._streamName.indexOf("/fms/fpad") >= 0)
  356.       {
  357.          this.connectFPAD(this._streamName);
  358.       }
  359.       else
  360.       {
  361.          if(this._autoSenseBW)
  362.          {
  363.             this.bitrateMatch();
  364.          }
  365.          this.connectHTTP();
  366.          this._owner.ncConnected();
  367.       }
  368.    }
  369.    function bitrateMatch()
  370.    {
  371.       var _loc3_ = undefined;
  372.       var _loc4_ = this._bitrate;
  373.       if(isNaN(_loc4_))
  374.       {
  375.          _loc4_ = 0;
  376.       }
  377.       var _loc2_ = 0;
  378.       while(_loc2_ < this._streams.length)
  379.       {
  380.          if(isNaN(this._streams[_loc2_].bitrate) || _loc4_ >= this._streams[_loc2_].bitrate)
  381.          {
  382.             _loc3_ = _loc2_;
  383.             break;
  384.          }
  385.          _loc2_ = _loc2_ + 1;
  386.       }
  387.       if(isNaN(_loc3_))
  388.       {
  389.          throw new mx.video.VideoError(mx.video.VideoError.NO_BITRATE_MATCH);
  390.       }
  391.       if(this._streamName != undefined)
  392.       {
  393.          this._streamName += this._streams[_loc3_].src;
  394.       }
  395.       else
  396.       {
  397.          this._streamName = this._streams[_loc3_].src;
  398.       }
  399.       if(this._isRTMP && this._streamName.slice(-4).toLowerCase() == ".flv")
  400.       {
  401.          this._streamName = this._streamName.slice(0,-4);
  402.       }
  403.       this._streamLength = this._streams[_loc3_].dur;
  404.    }
  405.    function parseURL(url)
  406.    {
  407.       var _loc2_ = new Object();
  408.       var _loc3_ = 0;
  409.       var _loc4_ = url.indexOf(":/",_loc3_);
  410.       if(_loc4_ >= 0)
  411.       {
  412.          _loc4_ += 2;
  413.          _loc2_.protocol = url.slice(_loc3_,_loc4_);
  414.          _loc2_.isRelative = false;
  415.       }
  416.       else
  417.       {
  418.          _loc2_.isRelative = true;
  419.       }
  420.       if(_loc2_.protocol != undefined && (_loc2_.protocol == "rtmp:/" || _loc2_.protocol == "rtmpt:/" || _loc2_.protocol == "rtmps:/" || _loc2_.protocol == "rtmpe:/" || _loc2_.protocol == "rtmpte:/"))
  421.       {
  422.          _loc2_.isRTMP = true;
  423.          _loc3_ = _loc4_;
  424.          if(url.charAt(_loc3_) == "/")
  425.          {
  426.             _loc3_ = _loc3_ + 1;
  427.             var _loc7_ = url.indexOf(":",_loc3_);
  428.             var _loc8_ = url.indexOf("/",_loc3_);
  429.             if(_loc8_ < 0)
  430.             {
  431.                if(_loc7_ < 0)
  432.                {
  433.                   _loc2_.serverName = url.slice(_loc3_);
  434.                }
  435.                else
  436.                {
  437.                   _loc4_ = _loc7_;
  438.                   _loc2_.portNumber = url.slice(_loc3_,_loc4_);
  439.                   _loc3_ = _loc4_ + 1;
  440.                   _loc2_.serverName = url.slice(_loc3_);
  441.                }
  442.                return _loc2_;
  443.             }
  444.             if(_loc7_ >= 0 && _loc7_ < _loc8_)
  445.             {
  446.                _loc4_ = _loc7_;
  447.                _loc2_.serverName = url.slice(_loc3_,_loc4_);
  448.                _loc3_ = _loc4_ + 1;
  449.                _loc4_ = _loc8_;
  450.                _loc2_.portNumber = url.slice(_loc3_,_loc4_);
  451.             }
  452.             else
  453.             {
  454.                _loc4_ = _loc8_;
  455.                _loc2_.serverName = url.slice(_loc3_,_loc4_);
  456.             }
  457.             _loc3_ = _loc4_ + 1;
  458.          }
  459.          if(url.charAt(_loc3_) == "?")
  460.          {
  461.             var _loc9_ = url.slice(_loc3_ + 1);
  462.             var _loc6_ = this.parseURL(_loc9_);
  463.             if(_loc6_.protocol == undefined || !_loc6_.isRTMP)
  464.             {
  465.                throw new mx.video.VideoError(mx.video.VideoError.INVALID_CONTENT_PATH,url);
  466.             }
  467.             _loc2_.wrappedURL = "?";
  468.             _loc2_.wrappedURL += _loc6_.protocol;
  469.             if(_loc6_.serverName != undefined)
  470.             {
  471.                _loc2_.wrappedURL += "/";
  472.                _loc2_.wrappedURL += _loc6_.serverName;
  473.             }
  474.             if(_loc6_.wrappedURL != undefined)
  475.             {
  476.                _loc2_.wrappedURL += "/?";
  477.                _loc2_.wrappedURL += _loc6_.wrappedURL;
  478.             }
  479.             _loc2_.appName = _loc6_.appName;
  480.             _loc2_.streamName = _loc6_.streamName;
  481.             return _loc2_;
  482.          }
  483.          _loc4_ = url.indexOf("/",_loc3_);
  484.          if(_loc4_ < 0)
  485.          {
  486.             _loc2_.appName = url.slice(_loc3_);
  487.             return _loc2_;
  488.          }
  489.          _loc2_.appName = url.slice(_loc3_,_loc4_);
  490.          _loc3_ = _loc4_ + 1;
  491.          _loc4_ = url.indexOf("/",_loc3_);
  492.          if(_loc4_ < 0)
  493.          {
  494.             _loc2_.streamName = url.slice(_loc3_);
  495.             if(_loc2_.streamName.slice(-4).toLowerCase() == ".flv")
  496.             {
  497.                _loc2_.streamName = _loc2_.streamName.slice(0,-4);
  498.             }
  499.             return _loc2_;
  500.          }
  501.          _loc2_.appName += "/";
  502.          _loc2_.appName += url.slice(_loc3_,_loc4_);
  503.          _loc3_ = _loc4_ + 1;
  504.          _loc2_.streamName = url.slice(_loc3_);
  505.          if(_loc2_.streamName.slice(-4).toLowerCase() == ".flv")
  506.          {
  507.             _loc2_.streamName = _loc2_.streamName.slice(0,-4);
  508.          }
  509.       }
  510.       else
  511.       {
  512.          _loc2_.isRTMP = false;
  513.          _loc2_.streamName = url;
  514.       }
  515.       return _loc2_;
  516.    }
  517.    function canReuseOldConnection(parseResults)
  518.    {
  519.       if(this._nc == null || !this._ncConnected)
  520.       {
  521.          return false;
  522.       }
  523.       if(!parseResults.isRTMP)
  524.       {
  525.          if(!this._isRTMP)
  526.          {
  527.             return true;
  528.          }
  529.          this._owner.close();
  530.          this._nc = undefined;
  531.          this._ncConnected = false;
  532.          this.initNCInfo();
  533.          return false;
  534.       }
  535.       if(this._isRTMP)
  536.       {
  537.          if(parseResults.serverName == this._serverName && parseResults.appName == this._appName && parseResults.protocol == this._protocol && parseResults.portNumber == this._portNumber && parseResults.wrappedURL == this._wrappedURL)
  538.          {
  539.             return true;
  540.          }
  541.          this._owner.close();
  542.          this._nc = undefined;
  543.          this._ncConnected = false;
  544.       }
  545.       this.initNCInfo();
  546.       return false;
  547.    }
  548.    function connectHTTP()
  549.    {
  550.       this._nc = new NetConnection();
  551.       this._nc.connect(null);
  552.       this._ncConnected = true;
  553.       return true;
  554.    }
  555.    function connectRTMP()
  556.    {
  557.       clearInterval(this._timeoutIntervalId);
  558.       this._timeoutIntervalId = setInterval(this,"_onFCSConnectTimeOut",this._timeout);
  559.       this._tryNC = new Array();
  560.       var _loc3_ = !(this._protocol == "rtmp:/" || this._protocol == "rtmpe:/") ? 1 : 2;
  561.       var _loc2_ = 0;
  562.       while(_loc2_ < _loc3_)
  563.       {
  564.          this._tryNC[_loc2_] = new NetConnection();
  565.          if(this.fpadZone != null)
  566.          {
  567.             this._tryNC[_loc2_].fpadZone = this.fpadZone;
  568.          }
  569.          this._tryNC[_loc2_].mc = this;
  570.          this._tryNC[_loc2_].pending = false;
  571.          this._tryNC[_loc2_].connIndex = _loc2_;
  572.          this._tryNC[_loc2_].onBWDone = function(p_bw)
  573.          {
  574.             this.mc.onConnected(this,p_bw);
  575.          };
  576.          this._tryNC[_loc2_].onBWCheck = function()
  577.          {
  578.             return ++this.mc._payload;
  579.          };
  580.          this._tryNC[_loc2_].onStatus = function(info)
  581.          {
  582.             this.mc.connectOnStatus(this,info);
  583.          };
  584.          _loc2_ = _loc2_ + 1;
  585.       }
  586.       this.nextConnect();
  587.       return false;
  588.    }
  589.    function connectFPAD(url)
  590.    {
  591.       var _loc7_ = undefined;
  592.       var _loc5_ = undefined;
  593.       var _loc6_ = undefined;
  594.       var _loc2_ = url.indexOf("?");
  595.       while(_loc2_ >= 0)
  596.       {
  597.          _loc2_ = _loc2_ + 1;
  598.          var _loc4_ = url.indexOf("&",_loc2_);
  599.          if(url.substr(_loc2_,4).toLowerCase() == "uri=")
  600.          {
  601.             _loc7_ = url.slice(0,_loc2_);
  602.             _loc2_ += 4;
  603.             if(_loc4_ >= 0)
  604.             {
  605.                _loc5_ = url.slice(_loc2_,_loc4_);
  606.                _loc6_ = url.slice(_loc4_);
  607.             }
  608.             else
  609.             {
  610.                _loc5_ = url.slice(_loc2_);
  611.                _loc6_ = "";
  612.             }
  613.             break;
  614.          }
  615.          _loc2_ = _loc4_;
  616.       }
  617.       if(_loc2_ < 0)
  618.       {
  619.          throw new mx.video.VideoError(mx.video.VideoError.INVALID_CONTENT_PATH,"fpad url must include uri parameter: " + url);
  620.       }
  621.       var _loc8_ = this.parseURL(_loc5_);
  622.       if(!_loc8_.isRTMP)
  623.       {
  624.          throw new mx.video.VideoError(mx.video.VideoError.INVALID_CONTENT_PATH,"fpad url uri parameter must be rtmp url: " + url);
  625.       }
  626.       this._fpadMgr = new mx.video.FPADManager(this);
  627.       return this._fpadMgr.connectXML(_loc7_,_loc5_,_loc6_,_loc8_);
  628.    }
  629.    function nextConnect()
  630.    {
  631.       clearInterval(this._tryNCIntervalId);
  632.       this._tryNCIntervalId = 0;
  633.       var _loc3_ = undefined;
  634.       var _loc2_ = undefined;
  635.       if(this._connTypeCounter == 0)
  636.       {
  637.          _loc3_ = this._protocol;
  638.          _loc2_ = this._portNumber;
  639.       }
  640.       else
  641.       {
  642.          _loc2_ = null;
  643.          if(this._protocol == "rtmp:/")
  644.          {
  645.             _loc3_ = "rtmpt:/";
  646.          }
  647.          else
  648.          {
  649.             if(this._protocol != "rtmpe:/")
  650.             {
  651.                this._tryNC.pop();
  652.                return undefined;
  653.             }
  654.             _loc3_ = "rtmpte:/";
  655.          }
  656.       }
  657.       var _loc4_ = _loc3_ + (this._serverName != undefined ? "/" + this._serverName + (_loc2_ != null ? ":" + _loc2_ : "") + "/" : "") + (this._wrappedURL != undefined ? this._wrappedURL + "/" : "") + this._appName;
  658.       this._tryNC[this._connTypeCounter].pending = true;
  659.       this._tryNC[this._connTypeCounter].connect(_loc4_,this._autoSenseBW);
  660.       if(this._connTypeCounter < this._tryNC.length - 1)
  661.       {
  662.          this._connTypeCounter = this._connTypeCounter + 1;
  663.          this._tryNCIntervalId = setInterval(this,"nextConnect",1500);
  664.       }
  665.    }
  666.    function cleanConns()
  667.    {
  668.       clearInterval(this._tryNCIntervalId);
  669.       this._tryNCIntervalId = 0;
  670.       if(this._tryNC != undefined)
  671.       {
  672.          var _loc2_ = 0;
  673.          while(_loc2_ < this._tryNC.length)
  674.          {
  675.             if(this._tryNC[_loc2_] != undefined)
  676.             {
  677.                delete this._tryNC[_loc2_].onStatus;
  678.                if(this._tryNC[_loc2_].pending)
  679.                {
  680.                   this._tryNC[_loc2_].onStatus = function(info)
  681.                   {
  682.                      this.mc.disconnectOnStatus(this,info);
  683.                   };
  684.                }
  685.                else
  686.                {
  687.                   delete this._tryNC[_loc2_].onStatus;
  688.                   this._tryNC[_loc2_].close();
  689.                }
  690.             }
  691.             delete this._tryNC[_loc2_];
  692.             _loc2_ = _loc2_ + 1;
  693.          }
  694.          delete this._tryNC;
  695.       }
  696.    }
  697.    function tryFallBack()
  698.    {
  699.       if(this._serverName == this.fallbackServerName || this.fallbackServerName == undefined || this.fallbackServerName == null)
  700.       {
  701.          delete this._nc;
  702.          this._nc = undefined;
  703.          this._ncConnected = false;
  704.          this._owner.ncConnected();
  705.       }
  706.       else
  707.       {
  708.          this._connTypeCounter = 0;
  709.          this.cleanConns();
  710.          this._serverName = this.fallbackServerName;
  711.          this.connectRTMP();
  712.       }
  713.    }
  714.    function onConnected(p_nc, p_bw)
  715.    {
  716.       clearInterval(this._timeoutIntervalId);
  717.       this._timeoutIntervalId = 0;
  718.       delete p_nc.onBWDone;
  719.       delete p_nc.onBWCheck;
  720.       delete p_nc.onStatus;
  721.       this._nc = p_nc;
  722.       this._ncUri = this._nc.uri;
  723.       this._ncConnected = true;
  724.       if(this._autoSenseBW)
  725.       {
  726.          this._bitrate = p_bw * 1024;
  727.          if(this._streams != undefined)
  728.          {
  729.             this.bitrateMatch();
  730.          }
  731.          else
  732.          {
  733.             var _loc3_ = this._streamName.split(",");
  734.             var _loc2_ = 0;
  735.             while(_loc2_ < _loc3_.length)
  736.             {
  737.                var _loc4_ = mx.video.NCManager.stripFrontAndBackWhiteSpace(_loc3_[_loc2_]);
  738.                if(_loc2_ + 1 >= _loc3_.length)
  739.                {
  740.                   this._streamName = _loc4_;
  741.                   break;
  742.                }
  743.                if(p_bw <= Number(_loc3_[_loc2_ + 1]))
  744.                {
  745.                   this._streamName = _loc4_;
  746.                   break;
  747.                }
  748.                _loc2_ += 2;
  749.             }
  750.             if(this._streamName.slice(-4).toLowerCase() == ".flv")
  751.             {
  752.                this._streamName = this._streamName.slice(0,-4);
  753.             }
  754.          }
  755.       }
  756.       if(!this._owner.isLive && this._streamLength == undefined)
  757.       {
  758.          var _loc6_ = new Object();
  759.          _loc6_.mc = this;
  760.          _loc6_.onResult = function(length)
  761.          {
  762.             this.mc.getStreamLengthResult(length);
  763.          };
  764.          this._nc.call("getStreamLength",_loc6_,this._streamName);
  765.       }
  766.       else
  767.       {
  768.          this._owner.ncConnected();
  769.       }
  770.    }
  771.    function connectOnStatus(target, info)
  772.    {
  773.       target.pending = false;
  774.       if(info.code == "NetConnection.Connect.Success")
  775.       {
  776.          this._nc = this._tryNC[target.connIndex];
  777.          this._tryNC[target.connIndex] = undefined;
  778.          this.cleanConns();
  779.       }
  780.       else if(info.code == "NetConnection.Connect.Rejected" && info.ex != null && info.ex.code == 302)
  781.       {
  782.          this._connTypeCounter = 0;
  783.          this.cleanConns();
  784.          var _loc2_ = this.parseURL(info.ex.redirect);
  785.          if(_loc2_.isRTMP)
  786.          {
  787.             this._protocol = _loc2_.protocol;
  788.             this._serverName = _loc2_.serverName;
  789.             this._wrappedURL = _loc2_.wrappedURL;
  790.             this._portNumber = _loc2_.portNumber;
  791.             this._appName = _loc2_.appName;
  792.             if(_loc2_.streamName != null)
  793.             {
  794.                this._appName += "/" + _loc2_.streamName;
  795.             }
  796.             this.connectRTMP();
  797.          }
  798.          else
  799.          {
  800.             this.tryFallBack();
  801.          }
  802.       }
  803.       else if((info.code == "NetConnection.Connect.Failed" || info.code == "NetConnection.Connect.Rejected") && target.connIndex == this._tryNC.length - 1)
  804.       {
  805.          if(!this.connectAgain())
  806.          {
  807.             this.tryFallBack();
  808.          }
  809.       }
  810.    }
  811.    function reconnectOnStatus(target, info)
  812.    {
  813.       if(info.code == "NetConnection.Connect.Failed" || info.code == "NetConnection.Connect.Rejected")
  814.       {
  815.          delete this._nc;
  816.          this._nc = undefined;
  817.          this._ncConnected = false;
  818.          this._owner.ncReconnected();
  819.       }
  820.    }
  821.    function disconnectOnStatus(target, info)
  822.    {
  823.       if(info.code == "NetConnection.Connect.Success")
  824.       {
  825.          delete target.onStatus;
  826.          target.close();
  827.       }
  828.    }
  829.    function getStreamLengthResult(length)
  830.    {
  831.       if(length > 0)
  832.       {
  833.          this._streamLength = length;
  834.       }
  835.       this._owner.ncConnected();
  836.    }
  837.    function _onFCSConnectTimeOut()
  838.    {
  839.       this.cleanConns();
  840.       this._nc = undefined;
  841.       this._ncConnected = false;
  842.       if(!this.connectAgain())
  843.       {
  844.          this._owner.ncConnected();
  845.       }
  846.    }
  847.    static function stripFrontAndBackWhiteSpace(p_str)
  848.    {
  849.       var _loc1_ = undefined;
  850.       var _loc2_ = p_str.length;
  851.       var _loc4_ = 0;
  852.       var _loc5_ = _loc2_;
  853.       _loc1_ = 0;
  854.       while(_loc1_ < _loc2_)
  855.       {
  856.          switch(p_str.charCodeAt(_loc1_))
  857.          {
  858.             case 9:
  859.             case 10:
  860.             case 13:
  861.             case 32:
  862.                break;
  863.             default:
  864.                _loc4_ = _loc1_;
  865.          }
  866.          _loc1_ = _loc1_ + 1;
  867.       }
  868.       _loc1_ = _loc2_;
  869.       while(_loc1_ >= 0)
  870.       {
  871.          switch(p_str.charCodeAt(_loc1_))
  872.          {
  873.             case 9:
  874.             case 10:
  875.             case 13:
  876.             case 32:
  877.                break;
  878.             default:
  879.                _loc5_ = _loc1_ + 1;
  880.          }
  881.          _loc1_ = _loc1_ - 1;
  882.       }
  883.       if(_loc5_ <= _loc4_)
  884.       {
  885.          return "";
  886.       }
  887.       return p_str.slice(_loc4_,_loc5_);
  888.    }
  889. }
  890.